Amazon Simple Queue Service (Amazon SQS)
💡 Definition
Amazon Simple Queue Service (Amazon SQS) is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications. SQS eliminates the complexity of managing and operating message oriented middleware, and lets you send, store, and receive messages between software components at any volume, without losing messages or requiring other services to be available.
🔑 Key Concepts
- Message Queues: A temporary repository for messages that are waiting to be processed.
- Decoupling: Allows message producers and consumers to interact asynchronously without being directly connected, improving fault tolerance and scalability.
- Pull-Based: Consumers "pull" messages from the queue (rather than messages being "pushed" to them like in SNS).
- Message Durability: Messages are stored redundantly across multiple AZs until they are processed and deleted.
- Types of Queues:
- Standard Queues: Offer maximum throughput, best-effort ordering, and at-least-once delivery.
- FIFO (First-In, First-Out) Queues: Guarantee that messages are processed exactly once, in the exact order that they are sent.
- Visibility Timeout: A period during which a message is hidden from other consumers after it has been received by one, preventing duplicate processing.
⚙️ How it Works
A component (producer) sends messages to an SQS queue. Another component (consumer), such as an EC2 instance or a Lambda function, retrieves messages from the queue, processes them, and then deletes them from the queue. If a consumer fails to process a message, the message becomes visible again after the visibility timeout expires, allowing another consumer to attempt processing.
🎯 Use Cases
- Decoupling Microservices: Ensuring that failures in one service don't impact others.
- Buffering Workloads: Handling bursts of activity by buffering incoming requests, allowing consumers to process them at a steady rate.
- Asynchronous Processing: Offloading tasks that don't require immediate responses (e.g., image processing, email sending).
- Distributed Polling: Managing a large number of tasks to be processed by a fleet of workers.
💰 Pricing Model
- Per Million Requests: Charged per million requests (API calls) to SQS.
- Data Transfer: Standard data transfer rates apply.
📝 Exam Tips (CLF-C02)
- Keywords: "Message queuing", "Decouple", "Asynchronous", "Pull-based", "Buffering".
- Remember SQS is a pull-based service for decoupling components, ensuring reliable message delivery.
- Distinguish from SNS (push-based, fanout to multiple subscribers). SNS can deliver messages to SQS queues.
- Know the difference between Standard and FIFO queues (ordering and exactly-once processing for FIFO).
See Also: * SNS * Lambda * EC2 * EventBridge